﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gao.Poker.Domain;

namespace Gao.Poker.Services
{
    public class ConsumptionService : BaseService
    {
        private static ConsumptionService _instance;

        public static ConsumptionService Instance()
        {
            return _instance ?? (_instance = new ConsumptionService());
        }

        private ConsumptionService()
        {
            
        }

        public List<Consumption> Search()
        {
            return DbContext.Consumptions.ToList();
        }

        public List<Consumption> GetPageList(String name, String cardNo, int pageIndex, int pageSize)
        {
            return DbContext.Consumptions.Where(a=>a.MemberCardNo.Contains(cardNo))
                .Where(a=>a.MemberName.Contains(name))
                .OrderBy(a => a.ID).Skip(pageIndex * pageSize).Take(pageSize).ToList();
        }

        public Int32 GetTotal(String name, String cardNo)
        {
            return DbContext.Consumptions.Where(a => a.MemberCardNo.Contains(cardNo)).Count(a => a.MemberName.Contains(name));
        }

        public Consumption Save(Consumption consumption)
        {
            DbContext.Consumptions.Add(consumption);
            DbContext.SaveChanges();
            return consumption;
        }
    }
}
